<template>
  <div class="app-container">
    <!-- 按钮 -->
    <el-card class="box-card" style="margin-top: 10px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="buttonMethod(1)"
            v-hasPermi="['charge:feeStandardsProject:prepaidProject:add']"
            >新增
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card" style="margin-top: 10px">
      <el-table :data="dataList" stripe border>
        <el-table-column label="预交费项目" prop="projectName" />
        <el-table-column label="操作人" prop="createBy" />
        <el-table-column label="创建时间" prop="createTime" />
        <el-table-column label="操作" width="260" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="buttonMethod(2, scope.row)"
              v-hasPermi="['charge:feeStandardsProject:prepaidProject:edit']"
              >修改
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 添加、编辑 -->
    <el-dialog :title="title" :visible.sync="status" width="30%">
      <el-form label-width="120px" label-position="right" size="small" class="formBox">
        <el-row class="mb_10">
          <el-col :span="20">
            <el-form-item label="预交费项目：" class="is-required">
              <el-input
                placeholder="请输入预交费项目"
                maxlength="50"
                show-word-limit
                v-model="queryForm.projectName"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="buttonMethod(3)">取 消</el-button>
        <el-button type="primary" @click="buttonMethod(4)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { queryPrepaymentList, addPrepayment, updatePrepayment } from "@/api/charge";
export default {
  name: "",
  dicts: ["campus_status"],
  data() {
    return {
      status: false,
      title: "",
      dataList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      queryForm: {},
      total: 0,
      showSearch: true,
      date: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取列表数据
    getList() {
      var that = this;
      var data = this.queryParams;
      queryPrepaymentList(data).then((res) => {
        if (res.code == 200) {
          that.dataList = res.rows;
          that.total = res.total;
        }
      });
    },
    /**
     * 按钮点击事件处理方法
     */
    buttonMethod(options, value) {
      var that = this;
      //options 等于 1
      if (options == 1) {
        that.queryForm = {};
        that.title = "添加";
        that.status = true;
      }
      //options 等于 2 关闭弹窗
      else if (options == 2) {
        that.queryForm = value;
        that.title = "修改";
        that.status = true;
      }
      //options 等于 3 关闭弹窗
      else if (options == 3) {
        that.queryForm = {};
        that.title = "";
        that.status = false;
      }
      // 添加、修改按钮点击事件处理方法
      else if (options == 4) {
        var data = that.queryForm;
        if (!data.projectName) {
          return that.$message.error("请输入预交费项目");
        }
        if (data.id) {
          updatePrepayment(data).then((res) => {
            if (res.code == 200) {
              that.queryForm = {};
              that.title = "";
              that.status = false;
              that.$message.success(res.msg);
              that.getList();
            } else {
              that.$message.error(res.msg);
            }
          });
        } else {
          addPrepayment(data).then((res) => {
            if (res.code == 200) {
              that.queryForm = {};
              that.title = "";
              that.status = false;
              that.getList();
              that.$message.success(res.msg);
            } else {
              that.$message.error(res.msg);
            }
          });
        }
      }
    },
    /**
     * 处理查询请求
     *
     * 将查询参数中的页码重置为1，并调用getList方法获取列表数据
     */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /**
     * 重置查询表单并重新执行查询操作
     */
    resetQuery() {
      this.date = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style scoped>
.width_100 {
  width: 100%;
}
</style>
